Create directory through C# using WinSCP on SFTP server -


we writing console application in c# upload files, through winscp .net assembly using sftp protocol, file server. able connect server , place files server not @ exact place want. please find code below:

where

path = \repository\scan\java\ant\uat zippath = c:\temp\uat_17-11-2016-19_40_05.zip sftppath = \repository\scan\java\ant\uat\uat_17-11-2016-19_40_05.zip 

zip file getting placed @ repository folder level name repositoryscanjavaantuatuat_17-11-2016-19_40_05.zip. if directories don't exist on server not getting created.

using (session session = new session()) {     session.open(sessionoptions);     {         if (system.io.directory.exists(path))         {             console.writeline("that path exists already.");         }         else         {             directoryinfo di = system.io.directory.createdirectory(path);             console.writeline(                 "the directory created @ {0}.",                 system.io.directory.getcreationtime(path));         }          try         {             console.writeline("put files in folder");             transferoptions transferoptions = new transferoptions();             transferoptions.transfermode = transfermode.binary;             transferoperationresult transferresult;             transferresult = session.putfiles(zippath, sftppath, false, transferoptions);             transferresult.check();         }                         catch (exception e)         {             console.writeline("the process failed: {0}", e.tostring());         }     } } 

thanks in advance!

  • you cannot use system.io.directory.exists check existence of sftp directory, nor can use system.io.directory.createdirectory create directory on sftp server. use winscp session.fileexists , session.createdirectory methods:

    if (session.fileexists(path)) {     console.writeline("that path exists already."); } else {     session.createdirectory(path);     console.writeline("the directory created successfully"); } 
  • the sftp paths use slash, not backslash:

    path = /repository/scan/java/ant/uat sftppath = /repository/scan/java/ant/uat/uat_17-11-2016-19_40_05.zip 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -