Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: All steps OK but not getting the files in .net

You probably want to add a backslash between the localPath and the *.

If this does not help, please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
Pimhach

All steps OK but not getting the files in .NET

I have a task to do SFTP in a .NET program. Everything is fine except that we are not getting back the files. In Debugging am not getting any errors in the steps but problem is no files coming back. in the manual SCP, we have to copy paste the files that come back, we wanted to automate this.

App.config
<appSettings>
    <add key="HostName" value="Groups.sftp.myhub.com" />
    <add key="UserName" value="Groups" />
    <add key="Password" value="mypassword" />
    <add key="SshHostKeyFingerprint" value="ssh-rsa 2047 za:5z:z6:77:36:d6:94:89:44:15:b0:ca:59:bf:d3:92" />
    <add key="LocalPath" value="\\server-app01\cust\SC\AMAZON\WINSCP\TESTAMAZON" />
    <!-- this is local folder path -->
    <add key="RemotePath" value="/outgoing/orders/AMAZON/" />
    <!--   this is remote system directory path -->
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>

Program.cs
// Setup session options SessionOptions
sessionOptions = new SessionOptions {
    //Passing HostName , Password, & UserName here. port number
    Protocol = Protocol.Sftp,
    HostName = ConfigurationManager.AppSettings["HostName"].ToString(),
    UserName = ConfigurationManager.AppSettings["UserName"].ToString(),
    Password = ConfigurationManager.AppSettings["Password"].ToString(),
    SshHostKeyFingerprint = ConfigurationManager.AppSettings["SshHostKeyFingerprint"].ToString()
};
string LocalPath = ConfigurationManager.AppSettings["LocalPath"].ToString();
string RemotePath = ConfigurationManager.AppSettings["RemotePath"].ToString();
 
using (Session session = new Session())
{
    // Connect
    session.Open(sessionOptions);
 
    // Upload files
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary;
 
    TransferOperationResult transferResult;
    transferResult = session.PutFiles(LocalPath + "*", RemotePath, false, transferOptions);
 
    // Throw on any error
    transferResult.Check();
}