本文整理汇总了C#中Renci.SshNet.SftpClient类的典型用法代码示例。如果您正苦于以下问题:C# SftpClient类的具体用法?C# SftpClient怎么用?C# SftpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SftpClient类属于Renci.SshNet命名空间,在下文中一共展示了SftpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CopyFileFromRemoteToLocal
public static void CopyFileFromRemoteToLocal(string host, string user, string password, string localPath, string remotePath)
{
using (SftpClient client = new SftpClient(host, user, password))
{
client.KeepAliveInterval = TimeSpan.FromSeconds(60);
client.ConnectionInfo.Timeout = TimeSpan.FromMinutes(180);
client.OperationTimeout = TimeSpan.FromMinutes(180);
client.Connect();
bool connected = client.IsConnected;
// RunCommand(host, user, password, "sudo chmod 777 -R " + remotePath);
var file = File.OpenWrite(localPath);
client.DownloadFile(remotePath, file);
file.Close();
client.Disconnect();
}
}
开发者ID:wangn6,项目名称:rep2,代码行数:17,代码来源:SSHWrapper.cs
示例2: PollHandler
private void PollHandler()
{
var exchange = new Exchange(_processor.Route);
var ipaddress = _processor.UriInformation.GetUriProperty("host");
var username = _processor.UriInformation.GetUriProperty("username");
var password = _processor.UriInformation.GetUriProperty("password");
var destination = _processor.UriInformation.GetUriProperty("destination");
var port = _processor.UriInformation.GetUriProperty<int>("port");
var interval = _processor.UriInformation.GetUriProperty<int>("interval", 100);
var secure = _processor.UriInformation.GetUriProperty<bool>("secure");
do
{
Thread.Sleep(interval);
try
{
if (secure)
{
SftpClient sftp = null;
sftp = new SftpClient(ipaddress, port, username, password);
sftp.Connect();
foreach (var ftpfile in sftp.ListDirectory("."))
{
var destinationFile = Path.Combine(destination, ftpfile.Name);
using (var fs = new FileStream(destinationFile, FileMode.Create))
{
var data = sftp.ReadAllText(ftpfile.FullName);
exchange.InMessage.Body = data;
if (!string.IsNullOrEmpty(data))
{
sftp.DownloadFile(ftpfile.FullName, fs);
}
}
}
}
else
{
ReadFtp(exchange);
}
}
catch (Exception exception)
{
var msg = exception.Message;
}
} while (true);
}
开发者ID:ojoadeolagabriel,项目名称:TqWorkflow-beta,代码行数:48,代码来源:FtpConsumer.cs
示例3: Uploadfiles
private void Uploadfiles(PasswordConnectionInfo connectionInfo, IEnumerable<AchFileEntity> achFilesToUpload)
{
using (var sftp = new SftpClient(connectionInfo))
{
try
{
sftp.Connect();
foreach (var achfile in achFilesToUpload)
{
using (var stream = new MemoryStream())
{
var fileName = achfile.Name + ".ach";
var writer = new StreamWriter(stream);
// writer.Write(achfile.AchFileBody);
writer.Flush();
stream.Position = 0;
sftp.UploadFile(stream, fileName);
this.Manager.ChangeAchFilesStatus(achfile, AchFileStatus.Uploaded);
this.Manager.UnLock(achfile);
}
}
}
finally
{
sftp.Disconnect();
}
}
}
开发者ID:rconnelly,项目名称:ach.fulfillment,代码行数:31,代码来源:UploadAchFilesJob.cs
示例4: sendSFTP
private void sendSFTP(string filePath, string fileName)
{
SftpClient sftp = new SftpClient("194.2.93.194", "userece", "AdminPOCNUC01");
sftp.Connect();
using (FileStream filestream = File.OpenRead(filePath))
{
sftp.UploadFile(filestream, "/"+fileName, null);
sftp.Disconnect();
}
}
开发者ID:CapG,项目名称:POC_WIPlugin_DatasExporter,代码行数:10,代码来源:IVRExportAsset.cs
示例5: CopyFileFromLocalToRemote
public static void CopyFileFromLocalToRemote(string host, string user, string password, string localPath, string remotePath)
{
using (SftpClient client = new SftpClient(host, user, password))
{
client.KeepAliveInterval = TimeSpan.FromSeconds(60);
client.ConnectionInfo.Timeout = TimeSpan.FromMinutes(180);
client.OperationTimeout = TimeSpan.FromMinutes(180);
client.Connect();
bool connected = client.IsConnected;
// RunCommand(host, user, password, "sudo chmod 777 -R " + remotePath);
FileInfo fi = new FileInfo(localPath);
client.UploadFile(fi.OpenRead(), remotePath + fi.Name, true);
client.Disconnect();
}
}
开发者ID:wangn6,项目名称:rep2,代码行数:15,代码来源:SSHWrapper.cs
示例6: GetList
public static IEnumerable<SftpFile> GetList(string host, string folder, string userName, string password)
{
using (var sftp = new SftpClient(host, userName, password))
{
sftp.ErrorOccurred += Sftp_ErrorOccurred;
sftp.Connect();
var toReturn = sftp.ListDirectory(folder).ToList();
sftp.Disconnect();
return toReturn;
}
}
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:15,代码来源:SftpManager.cs
示例7: SshFactory
public SshFactory(String host, String username, String password)
{
_connection = new SshClient(host, username, password);
_connection.Connect();
_sftp = new SftpClient(_connection.ConnectionInfo);
_sftp.Connect();
}
开发者ID:a1binos,项目名称:SystemInteract.Net,代码行数:7,代码来源:SshFactory.cs
示例8: AddToSftpSessionCollection
public static SftpSession AddToSftpSessionCollection(SftpClient sftpclient, SessionState pssession)
{
//Set initial variables
var obj = new SftpSession();
var sftpSessions = new List<SftpSession>();
var index = 0;
// Retrive existing sessions from the globla variable.
var sessionvar = pssession.PSVariable.GetValue("Global:SFTPSessions") as List<SftpSession>;
// If sessions exist we set the proper index number for them.
if (sessionvar != null && sessionvar.Count > 0)
{
sftpSessions.AddRange(sessionvar);
// Get the SessionId of the last item and count + 1
SftpSession lastSession = sftpSessions[sftpSessions.Count - 1];
index = lastSession.SessionId + 1;
}
// Create the object that will be saved
obj.SessionId = index;
obj.Host = sftpclient.ConnectionInfo.Host;
obj.Session = sftpclient;
sftpSessions.Add(obj);
// Set the Global Variable for the sessions.
pssession.PSVariable.Set((new PSVariable("Global:SFTPSessions", sftpSessions, ScopedItemOptions.AllScope)));
return obj;
}
开发者ID:darkoperator,项目名称:Posh-SSH,代码行数:30,代码来源:SshModHelper.cs
示例9: SFTPHelper
public SFTPHelper()
{
if (client == null)
{
client = new SftpClient(Host, Port, SFtpUserID, SFtpPassword);
}
}
开发者ID:MF2567346284,项目名称:BusinessManage,代码行数:7,代码来源:SFTPHelper.cs
示例10: TransferPluginSftp
public TransferPluginSftp (ConnectionData data) : base (data)
{
if (data.Password != null)
this.sftp = new SftpClient (data.Host, data.Port, data.User, data.Password);
else
this.sftp = new SftpClient (data.Host, data.Port, data.User, data.PrivateKey);
}
开发者ID:modulexcite,项目名称:Rainbows,代码行数:7,代码来源:TransferPluginSftp.cs
示例11: SFTP
public SFTP(FTPAccount account)
{
this.FTPAccount = account;
if (FTPAccount.UserName.Contains("@"))
{
FTPAccount.UserName = FTPAccount.UserName.Substring(0, FTPAccount.UserName.IndexOf('@'));
}
if (!string.IsNullOrEmpty(FTPAccount.Password) && (string.IsNullOrEmpty(FTPAccount.Keypath)))
{
client = new SftpClient(FTPAccount.Host, FTPAccount.Port, FTPAccount.UserName, FTPAccount.Password);
}
else if (string.IsNullOrEmpty(FTPAccount.Password) && (File.Exists(FTPAccount.Keypath)) && (string.IsNullOrEmpty(FTPAccount.Passphrase)))
{
client = new SftpClient(FTPAccount.Host, FTPAccount.Port, FTPAccount.UserName, new PrivateKeyFile(FTPAccount.Keypath));
}
else if (string.IsNullOrEmpty(FTPAccount.Password) && (File.Exists(FTPAccount.Keypath)) && (!string.IsNullOrEmpty(FTPAccount.Passphrase)))
{
client = new SftpClient(FTPAccount.Host, FTPAccount.Port, FTPAccount.UserName, new PrivateKeyFile(FTPAccount.Keypath, FTPAccount.Passphrase));
}
else
{
//Need to do something here...
DebugHelper.WriteLine("Can't instantiate a SFTP client...");
IsInstantiated = false;
return;
}
IsInstantiated = true;
}
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:29,代码来源:sftp.cs
示例12: DownloadFilesWithSftpAsync
private async Task DownloadFilesWithSftpAsync(Endpoint endpoint, string decodedPass)
{
var client = new SftpClient(endpoint.Url, endpoint.Username, decodedPass);
client.Connect();
SftpFile[] filesOnServer =
(await this.ListRemoteDirectoriesAsync(client, endpoint.RemoteDirectory)).Where(
x => !this.excludedListOfFiles.Any(y => x.Name.Equals(y))).ToArray();
var primaryLocalDirectory = endpoint.Destinations.FirstOrDefault(x => x.Type == DestinationType.Primary);
var archiveLocalDirectory = endpoint.Destinations.FirstOrDefault(x => x.Type == DestinationType.Archive);
var primaryAndArchiveAreNotExisting = primaryLocalDirectory == null || archiveLocalDirectory == null;
if (primaryAndArchiveAreNotExisting)
{
progress.ReportLine("You haven't provided the primary or archive folder");
return;
}
var filteredLocalFiles = FilterLocalFiles(filesOnServer, GetFilesListInFolder(primaryLocalDirectory.Name));
await this.GetFilesAsync(filteredLocalFiles, endpoint.RemoteDirectory, primaryLocalDirectory.Name, client).ContinueWith(x => client.Disconnect());
this.ArchiveFiles(GetFilesListInFolder(primaryLocalDirectory.Name), primaryLocalDirectory, archiveLocalDirectory);
}
开发者ID:dev4s,项目名称:2015-file-synchronizer,代码行数:25,代码来源:Synchronizer.cs
示例13: GangsSFTPDriver
public GangsSFTPDriver(string host, int port, string username, string password, string mountPoint)
: base(mountPoint, "SFTP")
{
this.host = host;
this.port = port;
this.sftpClient = new SftpClient(host, port, username, password);
}
开发者ID:ms-wannabe,项目名称:GangsDrive,代码行数:7,代码来源:GangsSFTPDriver.cs
示例14: SftpForm
public SftpForm(ConnectionInfo connectionInfo)
{
InitializeComponent();
this.connectionInfo = connectionInfo;
this.sftpClient = new SftpClient(this.connectionInfo);
this.sftpClient.Connect();
refresh();
}
开发者ID:KenjiOhtsuka,项目名称:SSHViewer,代码行数:8,代码来源:SftpForm.cs
示例15: SSHCommunication
public SSHCommunication(string server, string user, string password)
{
Server = server;
User = user;
Password = password;
sftp = new SftpClient(Server, User, Password);
sshClient = new SshClient(Server, User, Password);
}
开发者ID:lasttry,项目名称:APSCS.TestFramework,代码行数:9,代码来源:SSHCommunication.cs
示例16: UploadFileWithOpenConnection
public static void UploadFileWithOpenConnection(string localFileToUpload, string targetFile, SftpClient sftp)
{
var directory = FlatRedBall.IO.FileManager.GetDirectory(targetFile, FlatRedBall.IO.RelativeType.Relative);
CreateDirectoriesRecursively(directory, sftp);
using (var file = File.OpenRead(localFileToUpload))
{
sftp.UploadFile(file, targetFile, canOverride: true);
}
}
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:11,代码来源:SftpManager.cs
示例17: beginCracking
public void beginCracking()
{
log("beginning cracking process..");
var connectionInfo = new PasswordConnectionInfo (xml.Config.host, xml.Config.port, "root", xml.Config.Password);
using (var sftp = new SftpClient(connectionInfo))
{
using (var ssh = new SshClient(connectionInfo))
{
PercentStatus("Establishing SSH connection", 5);
ssh.Connect();
PercentStatus("Establishing SFTP connection", 10);
sftp.Connect();
log("Cracking " + ipaInfo.AppName);
PercentStatus("Preparing IPA", 25);
String ipalocation = AppHelper.extractIPA(ipaInfo);
using (var file = File.OpenRead(ipalocation))
{
log("Uploading IPA to device..");
PercentStatus("Uploading IPA", 40);
sftp.UploadFile(file, "Upload.ipa");
}
log("Cracking! (This might take a while)");
PercentStatus("Cracking", 50);
String binaryLocation = ipaInfo.BinaryLocation.Replace("Payload/", "");
String TempDownloadBinary = Path.Combine(AppHelper.GetTemporaryDirectory(), "crackedBinary");
var crack = ssh.RunCommand("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
log("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
log("cracking output: " + crack.Result);
using (var file = File.OpenWrite(TempDownloadBinary))
{
log("Downloading cracked binary..");
PercentStatus("Downloading cracked binary", 80);
try
{
sftp.DownloadFile("/tmp/crackedBinary", file);
}
catch (SftpPathNotFoundException e)
{
log("Could not find file, help!!!!!");
return;
}
}
PercentStatus("Repacking IPA", 90);
String repack = AppHelper.repack(ipaInfo, TempDownloadBinary);
PercentStatus("Done!", 100);
log("Cracking completed, file at " + repack);
}
}
}
开发者ID:koufengwei,项目名称:Brake,代码行数:54,代码来源:CrackProcess.cs
示例18: UploadFile
public static void UploadFile(string localFileToUpload, string host, string targetFile, string userName, string password)
{
using (var sftp = new SftpClient(host, userName, password))
{
sftp.OperationTimeout = new TimeSpan(0, 0, seconds: 40);
sftp.Connect();
UploadFileWithOpenConnection(localFileToUpload, targetFile, sftp);
sftp.Disconnect();
}
}
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:11,代码来源:SftpManager.cs
示例19: SFTP
public SFTP(Uri targetServer,string password)
{
_sftp = new SftpClient(targetServer.Host,targetServer.Port,
targetServer.UserInfo,
password);
log.InfoFormat("SFTP - Connecting to {0}", targetServer);
_sftp.Connect();
log.InfoFormat("SFTP - Changing dir to {0}", targetServer.LocalPath);
_sftp.ChangeDirectory(targetServer.LocalPath);
}
开发者ID:1aurent,项目名称:CloudBackup,代码行数:11,代码来源:SFTP.cs
示例20: DeleteRemoteDirectory
public static void DeleteRemoteDirectory(string host, string directory, string username, string password)
{
using (var sftp = new SftpClient(host, username, password))
{
sftp.Connect();
sftp.DeleteDirectory(directory);
sftp.Disconnect();
}
}
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:12,代码来源:SftpManager.cs
注:本文中的Renci.SshNet.SftpClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论