Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void upload_sftp(String filename)
- {
- String host="hostname.goeshere.com";
- String username="username";
- String password ="password";
- var workingdirectory = "./subfolder";
- String uploadFile = @"c:\\abc.txt";
- int port=22; //default value for SFTP client
- using (var client = new SftpClient(host, port, username, password))
- {
- client.Connect();
- if (client.IsConnected)
- {
- Console.WriteLine("Connected");
- client.ChangeDirectory(workingdirectory);
- using (var fileStream = new FileStream(uploadFile, FileMode.Open))
- {
- client.BufferSize = 4 * 1024;
- client.UploadFile(fileStream, filename); // if the same file name as from uploadfile - Path.GetFileName(uploadfile)
- }
- }
- else
- {
- Console.WriteLine("Not Connected");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement