2017-02-12 24 views
2

私はStack Overflowに関する多くの記事を読んだが、私は必要なものが見つからなかった。異なる拡張子を持つSFTPサーバーにファイルをアップロード

私はファイルを持っているが、私は正常に動作しているSFTPサーバにこのファイルをアップロードしたいtemp.csv

を想定します。

私はあなたがこの上で何かを提案してくださいすることができtemp.csv.ready

のような別の拡張子でこのファイルを保存する必要があります。

ここに私が試してうまく動作しているコードがあります。しかし、私はファイルの拡張子を変更することはできません。 Session.PutFiles method

SessionOptions sessionOptions = new SessionOptions 
{ 
    Protocol = Protocol.Sftp, 
    HostName = System.Configuration.ConfigurationManager.AppSettings["puthost"].ToString(), 
    UserName = System.Configuration.ConfigurationManager.AppSettings["putusername"].ToString(), 
    Password = System.Configuration.ConfigurationManager.AppSettings["putpassword"].ToString(), 
    PortNumber = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["putport"].ToString()), 
    SshHostKeyFingerprint = ... //followed by your 16 bit key 
}; 
using (Session session = new Session()) 
{ 
    session.SessionLogPath = "log.txt"; 
    session.Open(sessionOptions); //Attempts to connect to your sFtp site 
    //Get Ftp File 
    TransferOptions transferOptions = new TransferOptions(); 
    transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode - 
    //<em style="font-size: 9pt;">Automatic, Binary, or Ascii 
    transferOptions.FilePermissions = null; //Permissions applied to remote files; 
    //null for default permissions. Can set user, 
    //Group, or other Read/Write/Execute permissions. 
    transferOptions.PreserveTimestamp = false; //Set last write time of 
    //destination file to that of source file - basically change the timestamp 
    //to match destination and source files. 
    transferOptions.ResumeSupport.State = TransferResumeSupportState.Off; 
    WinSCP.TransferOperationResult transferResult; 
    //the parameter list is: local Path, Remote Path, Delete source file?, transfer Options 
    transferResult = session.PutFiles(@System.Configuration.ConfigurationManager.AppSettings["sendfilesource"].ToString(), System.Configuration.ConfigurationManager.AppSettings["sendfiletarget"].ToString(), false, transferOptions); 
} 

答えて

2

remotePath引数は次のとおりです。にファイルをアップロードする

フル・パス。

だから、あなたがする必要があるすべては、のような完全なパスを指定することです:あなたはライブラリを使用して喜んでいる場合

/remote/path/temp.csv.ready 
0

を、あなたは3rd library like componenentpro sftp library使用することをお勧めします。 client.UploadFile(@ "xxx \ temp.csv"、 "/temp.new.csv")でジョブを実行できます。このコード行は、次のコード例から抜粋したものです。

// Create a new class instance. 
Sftp client = new Sftp(); 

// Connect to the SFTP server. 
client.Connect("localhost"); 

// Authenticate. 
client.Authenticate("test", "test"); 

// ... 

// Upload local file 'c:\test.dat' to '/test.dat'. 
client.UploadFile(@"xxx\temp.csv", "/temp.new.csv"); 

// ... 

// Disconnect. 
client.Disconnect(); 
関連する問題