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); }
internal SftpLogFileInfoSharpSSH(Uri uri) { this.uri = uri; this.remoteFileName = uri.PathAndQuery; string userName = null; string password = null; if (uri.UserInfo != null && uri.UserInfo.Length > 0) { string[] split = uri.UserInfo.Split(new char[] { ':' }); if (split.Length > 0) { userName = split[0]; } if (split.Length > 1) { password = split[1]; } } if (userName == null || password == null) { IList <string> userNames = new List <string>(); LoginDialog dlg = new LoginDialog(uri.Host, userNames); dlg.UserName = userName; if (DialogResult.OK == dlg.ShowDialog()) { password = dlg.Password; userName = dlg.UserName; } } UserInfo userInfo = new SharpSshUserInfo(userName, password); JSch jsch = new JSch(); int port = uri.Port != -1 ? uri.Port : 22; Session session = jsch.getSession(userName, this.uri.Host, port); session.setUserInfo(userInfo); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); this.sftpChannel = (ChannelSftp)channel; SftpATTRS sftpAttrs = this.sftpChannel.lstat(this.remoteFileName); this.originalFileLength = sftpAttrs.getSize(); }
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); } }