static void Main(string[] args) { Sftp sftp = new Sftp("[SERVER]", "[USERNAME]", string.Empty); sftp.AddIdentityFile("[Path to Private kEY]"); sftp.Connect(); sftp.Put(@"D:\temp\blog\feed.csv", "[PATH OF FILE ON SERVER]"); sftp.Delete("[PATH OF FILE ON SERVER]"); }
public bool GetFiles() { bool status = true; Sftp sftp = new Sftp( m_sftpSite, m_sftpSiteUserName ); try { // add our private key to connect // put these in the config file sftp.AddIdentityFile(@"d:\apps\RSAKeys\opensshkey"); // connect sftp.Connect(); // get a directory list ArrayList rFiles = sftp.GetFileList( m_sftpSiteRemoteFolder ); foreach ( string file in rFiles ) { if (file.Equals(".") || file.Equals("..")) continue; // get the file and put in the watch folder to be processed sftp.Get(m_sftpSiteRemoteFolder + file, m_moveToProcessFolder + file); // update our database that we have downloaded the file from the server // this.updateDb( file ); // delete the file on the remote server after pulling it over // sftp.Delete(f); } sftp.Close(); status = true; } catch (Tamir.SharpSsh.jsch.SftpException se) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + se.Message); } catch (Tamir.SharpSsh.jsch.JSchException jse) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + jse.Message); } catch (Tamir.SharpSsh.SshTransferException ste) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + ste.Message); } catch (SystemException se) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + se.Message); } return status; }
private bool GetFiles() { bool status = true; Sftp sftp = new Sftp( m_sftpSite, m_sftpSiteUserName ); try { // add our private key to connect // put these in the config file sftp.AddIdentityFile( m_identityFile ); // connect sftp.Connect(); // get a directory list ArrayList rFiles = sftp.GetFileList( m_sftpSiteRemoteFolder ); int indx = 0; foreach ( string file in rFiles ) { indx++; if (file.Equals(".") || file.Equals("..")) continue; if ( this.CheckDb(file) ) continue; try { // get the file and put in the watch folder to be processed sftp.Get(m_sftpSiteRemoteFolder + file, m_moveToProcessFolder + file); // update the database to indicate file has been downloaded this.UpdateDb(file); // delete the file on the remote server after pulling it over // sftp.Delete(f); } catch (SystemException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:TryingToGetFile:" + indx + ":" + file + "::" + se.Message); } } sftp.Close(); status = true; } catch (Tamir.SharpSsh.jsch.SftpException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message); } catch (Tamir.SharpSsh.jsch.JSchException jse) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + jse.Message); } catch (Tamir.SharpSsh.SshTransferException ste) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + ste.Message); } catch (SystemException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message); } return status; }