Example #1
0
 public int SetAllocationSize(string filename, long length, DokanFileInfo info)
 {
     try
     {
         string      path    = GetPath(filename);
         ChannelSftp channel = GetChannel();
         SftpATTRS   attr    = channel.stat(path);
         if (attr.getSize() < length)
         {
             attr.setSIZE(length);
         }
         channel.setStat(path, attr);
     }
     catch (SftpException)
     {
         return(-1);
     }
     catch (Exception e)
     {
         connectionError_ = true;
         Debug(e.ToString());
         Reconnect();
         return(-1);
     }
     return(0);
 }
Example #2
0
        public int SetFileAttributes(
            String filename,
            FileAttributes attr,
            DokanFileInfo info)
        {
            Debug("SetFileAttributes {0}", filename);
            try
            {
                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();
                SftpATTRS   sattr   = channel.stat(path);

                int permissions = sattr.getPermissions();
                Debug(" permissons {0} {1}", permissions, sattr.getPermissionsString());
                sattr.setPERMISSIONS(permissions);
                channel.setStat(path, sattr);
                return(0);
            }
            catch (SftpException)
            {
                return(-1);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(-1);
            }
        }
Example #3
0
        public NtStatus SetEndOfFile(
            string filename,
            long length,
            DokanFileInfo info)
        {
            try
            {
                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();
                SftpATTRS   attr    = channel.stat(path);

                attr.setSIZE(length);
                channel.setStat(path, attr);

                return(NtStatus.Success);
            }
            catch (SftpException)
            {
                return(NtStatus.Error);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(NtStatus.Error);
            }
        }
Example #4
0
        public int SetFileTime(
            String filename,
            DateTime ctime,
            DateTime atime,
            DateTime mtime,
            DokanFileInfo info)
        {
            Debug("SetFileTime {0}", filename);
            try
            {
                Debug(" filetime {0} {1} {2}", ctime.ToString(), atime.ToString(), mtime.ToString());

                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();
                SftpATTRS   attr    = channel.stat(path);

                TimeSpan at = (atime - new DateTime(1970, 1, 1, 0, 0, 0));
                TimeSpan mt = (mtime - new DateTime(1970, 1, 1, 0, 0, 0));

                int uat = (int)at.TotalSeconds;
                int umt = (int)mt.TotalSeconds;

                if (mtime == DateTime.MinValue)
                {
                    umt = attr.getMTime();
                }
                if (atime == DateTime.MinValue)
                {
                    uat = attr.getATime();
                }

                attr.setACMODTIME(uat, umt);
                channel.setStat(path, attr);
                return(0);
            }
            catch (SftpException)
            {
                return(-1);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(-1);
            }
        }
Example #5
0
 private bool WritePermission(
     string path,
     int permission)
 {
     try
     {
         Debug("WritePermission {0}:{1}", path, Convert.ToString(permission, 8));
         ChannelSftp channel = GetChannel();
         SftpATTRS   attr    = channel.stat(path);
         attr.setPERMISSIONS(permission);
         channel.setStat(path, attr);
     }
     catch (SftpException)
     {
     }
     catch (Exception e)
     {
         connectionError_ = true;
         Debug(e.ToString());
         Reconnect();
     }
     return(true);
 }