Issue with the code

Advertisement

aman.jboy@...
Guest

Issue with the code

Hi,

I am trying to put the zip file from my system to sftp server using the following code.
Most of the information like sftpusername , sftppassword etc are self-explanatory. In case any information is required feel free to ask
But it is failing more often then not I am using WinSCP version 5.9.2 (build 6958). I am using the code below in C#.
The issue occurs when the WinSCP is not able to connect in 15 seconds. After that when it tries to it takes dir, ls as inputs for username and password rather than sftpusername and sftppassword.
winscp.StandardInput.WriteLine(sftpUsername);
//Console.WriteLine("Password: ----->" + sftppassword);
winscp.StandardInput.WriteLine(sftppassword);
// winscp.StandardInput.WriteLine("-hostkey=" +hostkey);
winscp.StandardInput.WriteLine("dir");
winscp.StandardInput.WriteLine("ls");
// Creating directories if not already present
winscp.StandardInput.WriteLine("mkdir " + path);
// Traversing to the required directory
winscp.StandardInput.WriteLine("cd " + path);
//Putting the zip file onto the server
winscp.StandardInput.WriteLine("put " + zippath);
winscp.StandardInput.Close();
string output = winscp.StandardOutput.ReadToEnd();
LogMessageToFile(output);
// completly shutting down the process
winscp.WaitForExit();

The attach log has the issue captured.

Is there a possibility to make it more robust and user-friendly.
Let me know in case any further details or information is required.

Thanks in Advance
  • WinSCP log.txt (5.08 KB, Private file)
Description: logs for the winscp code

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Issue with the code

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, use /log=path_to_log_file command-line argument. 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.

Though, you should use WinSCP .NET assembly instead:
https://winscp.net/eng/docs/library

Reply with quote

Advertisement

You can post new topics in this forum