Beispiel #1
0
 public int OpenDirectory(
     String filename,
     DokanFileInfo info)
 {
     Debug("OpenDirectory {0}", filename);
     try
     {
         string    path = GetPath(filename);
         SftpATTRS attr = GetChannel().stat(path);
         if (attr.isDir())
         {
             return(0);
         }
         else
         {
             return(-DokanNet.ERROR_PATH_NOT_FOUND); // TODO: return not directory?
         }
     }
     catch (SftpException e)
     {
         Debug(e.ToString());
         return(-DokanNet.ERROR_PATH_NOT_FOUND);
     }
     catch (Exception e)
     {
         connectionError_ = true;
         Debug(e.ToString());
         Reconnect();
         return(-DokanNet.ERROR_PATH_NOT_FOUND);
     }
 }
Beispiel #2
0
 public DokanError OpenDirectory(
     string filename,
     DokanFileInfo info)
 {
     Debug("OpenDirectory {0}", filename);
     try
     {
         string    path = GetPath(filename);
         SftpATTRS attr = GetChannel().stat(path);
         if (attr.isDir())
         {
             return(DokanError.ErrorSuccess);
         }
         else
         {
             return(DokanError.ErrorPathNotFound); // TODO: return not directory?
         }
     }
     catch (SftpException e)
     {
         Debug(e.ToString());
         return(DokanError.ErrorPathNotFound);
     }
     catch (Exception e)
     {
         connectionError_ = true;
         Debug(e.ToString());
         Reconnect();
         return(DokanError.ErrorPathNotFound);
     }
 }
Beispiel #3
0
 private bool isExist(string path, DokanFileInfo info)
 {
     try
     {
         ChannelSftp channel = GetChannel();
         SftpATTRS   attr    = channel.stat(path);
         if (attr.isDir())
         {
             info.IsDirectory = true;
         }
         return(true);
     }
     catch (SftpException)
     {
         return(false);
     }
 }
Beispiel #4
0
        public NtStatus GetFileInformation(
            string filename,
            out FileInformation fileinfo,
            DokanFileInfo info)
        {
            fileinfo = new FileInformation();
            try
            {
                string path = GetPath(filename);
                fileinfo.FileName = path;
                SftpATTRS attr = GetChannel().stat(path);

                fileinfo.Attributes = attr.isDir() ?
                                      FileAttributes.Directory :
                                      FileAttributes.Normal;

                if (DokanSSHFS.UseOffline)
                {
                    fileinfo.Attributes |= FileAttributes.Offline;
                }

                DateTime org = new DateTime(1970, 1, 1, 0, 0, 0, 0);

                fileinfo.CreationTime   = org.AddSeconds(attr.getMTime());
                fileinfo.LastAccessTime = org.AddSeconds(attr.getATime());
                fileinfo.LastWriteTime  = org.AddSeconds(attr.getMTime());
                fileinfo.Length         = attr.getSize();

                return(NtStatus.Success);
            }
            catch (SftpException)
            {
                return(NtStatus.Error);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(NtStatus.Error);
            }
        }
Beispiel #5
0
        public NtStatus CreateFile(
            string filename,
            DokanNet.FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            FileAttributes attributes,
            DokanFileInfo info)
        {
            if (info.IsDirectory)
            {
                switch (mode)
                {
                case FileMode.Open:
                    Debug("OpenDirectory {0}", filename);
                    try
                    {
                        string    path = GetPath(filename);
                        SftpATTRS attr = GetChannel().stat(path);
                        if (attr.isDir())
                        {
                            return(NtStatus.Success);
                        }
                        else
                        {
                            return(NtStatus.ObjectPathNotFound);    // TODO: return not directory?
                        }
                    }
                    catch (SftpException e)
                    {
                        Debug(e.ToString());
                        return(NtStatus.ObjectPathNotFound);
                    }
                    catch (Exception e)
                    {
                        connectionError_ = true;
                        Debug(e.ToString());
                        Reconnect();
                        return(NtStatus.ObjectPathNotFound);
                    }


                case FileMode.CreateNew:
                    Debug("CreateDirectory {0}", filename);
                    try
                    {
                        string      path    = GetPath(filename);
                        ChannelSftp channel = GetChannel();

                        channel.mkdir(path);
                        return(NtStatus.Success);
                    }
                    catch (SftpException e)
                    {
                        Debug(e.ToString());
                        return(NtStatus.Error);
                    }
                    catch (Exception e)
                    {
                        connectionError_ = true;
                        Debug(e.ToString());
                        Reconnect();
                        return(NtStatus.Error);    // TODO: more appropriate error code
                    }

                default:
                    Debug("Error FileMode invalid for directory {0}", mode);
                    return(NtStatus.Error);
                }
            }
            else
            {
                Debug("CreateFile {0}", filename);
                try
                {
                    string      path    = GetPath(filename);
                    ChannelSftp channel = GetChannel();

                    if (CheckAltStream(path))
                    {
                        return(NtStatus.Success);
                    }

                    switch (mode)
                    {
                    case FileMode.Open:
                    {
                        Debug("Open");
                        if (isExist(path, info))
                        {
                            return(NtStatus.Success);
                        }
                        else
                        {
                            return(NtStatus.ObjectNameNotFound);
                        }
                    }

                    case FileMode.CreateNew:
                    {
                        Debug("CreateNew");
                        if (isExist(path, info))
                        {
                            return(NtStatus.ObjectNameCollision);
                        }

                        Debug("CreateNew put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.Create:
                    {
                        Debug("Create put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.OpenOrCreate:
                    {
                        Debug("OpenOrCreate");

                        if (!isExist(path, info))
                        {
                            Debug("OpenOrCreate put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                        }
                        return(NtStatus.Success);
                    }

                    case FileMode.Truncate:
                    {
                        Debug("Truncate");

                        if (!isExist(path, info))
                        {
                            return(NtStatus.ObjectNameNotFound);
                        }

                        Debug("Truncate put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.Append:
                    {
                        Debug("Append");

                        if (isExist(path, info))
                        {
                            return(NtStatus.Success);
                        }

                        Debug("Append put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    default:
                        Debug("Error unknown FileMode {0}", mode);
                        return(NtStatus.Error);
                    }
                }
                catch (SftpException e)
                {
                    Debug(e.ToString());
                    return(NtStatus.ObjectNameNotFound);
                }
                catch (Exception e)
                {
                    connectionError_ = true;
                    Debug(e.ToString());
                    Reconnect();
                    return(NtStatus.ObjectNameNotFound);
                }
            }
        }