Error while downloading.

Advertisement

Ahsan
Guest

Error while downloading.

Hi.

I am trying to download a file to server. I passed username and key and connection is working perfectly. But when I download the file then it is not downloaded successfully and file name is also changed.I do not know why it happens.

Can anyone suggest what wrong is it? Here is below my code;
public bool GetSFTP()
        {
            string filename = string.Empty, outfilename = null, output = null, errmsg = null;

            // Run hidden WinSCP process
            Process winscp = new Process();
            string logname = Path.ChangeExtension(Path.GetTempFileName(), "xml");
            var _with1 = winscp.StartInfo;
            // SFTPExecutable needs to be defined in app.config to point to winscp.com
            try
            {
                _with1.FileName = ConfigurationSettings.AppSettings["SFTPExecutable"].ToString();
                if (_with1.FileName == null || _with1.FileName.Length == 0)
                {
                    EventLog.WriteEntry(logSource, "from GetSFTP: SFTPExecutable not set in config file.", EventLogEntryType.Warning);
                    throw (new Exception("from GetSFTP: SFTPExecutable not set in config file."));
                }
            }
            catch (Exception ex)
            {
                errmsg = ex.Message;
                EventLog.WriteEntry(logSource, errmsg, EventLogEntryType.Error);
                return false;
            }
            _with1.Arguments = "/log=" + logname;
            _with1.UseShellExecute = false;
            _with1.RedirectStandardInput = true;
            _with1.RedirectStandardOutput = true;
            _with1.CreateNoWindow = true;
            try
            {
                winscp.Start();
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(logSource, "from GetSFTP: Could not run the WinSCP executable.", EventLogEntryType.FailureAudit);
                errmsg = "from GetSFTP:  Could not run the WinSCP executable " + winscp.StartInfo.FileName + Environment.NewLine + ex.Message;
                return false;
            }

            // Feed in the scripting commands
            var _with2 = winscp.StandardInput;
            _with2.WriteLine("option batch abort");
            _with2.WriteLine("option confirm off");
            //_with2.WriteLine("open sftp://" + username + ":" + password + "@" + remotehost);
            _with2.WriteLine(" open " + Protocol + "://" + Username + "@" + Hostname + ":" + Port + " -privatekey=\"" + PublicKeyPath + "\"");
            _with2.WriteLine("cd /entitlement/ENT_7005");
            //_with2.WriteLine("put C:\\Ahsan_Test\\fwfi.log \"" + defaultRmDir + "\"");
            //_with2.WriteLine("exit");
            /*
            filename = "C:\\Ahsan_Test\\fwfi.log";
            if (outfilename == null)
                _with2.WriteLine("put " + filename);
            else
                _with2.WriteLine("put " + filename + " \"" + outfilename + "\"");
            */
            _with2.WriteLine("ls");
            _with2.WriteLine("get \"fwis.xml\" \"" + defaultLocalDir + "\"");
            _with2.Close();
            
            //Get winscp output
            //if ((output != null))
                output = winscp.StandardOutput.ReadToEnd();
            MessageBox.Show(output);
            // Wait until WinSCP finishes
            winscp.WaitForExit();

            // Parse and interpret the XML log
            // (Note that in case of fatal failure the log file may not exist at all)
            if (!File.Exists(logname))
            {
                errmsg = "from GetSFTP:  The WinSCP executable appears to have crashed.";
                EventLog.WriteEntry(logSource,errmsg, EventLogEntryType.FailureAudit);
                return false;
            }

            XPathDocument log = new XPathDocument(logname);
            XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
            ns.AddNamespace("w", "http://winscp.net/schema/session/1.0");
            XPathNavigator nav = log.CreateNavigator();
           
            // Success (0) or error?
            bool status = (winscp.ExitCode == 0);
            MessageBox.Show(status.ToString());
            if (!status)
            {
                errmsg = "from GetSFTP:  There was an error transferring " + filename + ".";
                // See if there are any messages associated with the error
                foreach (XPathNavigator message in nav.Select("//w:message", ns))
                {
                    errmsg += Environment.NewLine + message.Value;
                }
            }

            try
            {
                File.Delete(logname);
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "SFTP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EventLog.WriteEntry(logSource, ex.Message, EventLogEntryType.FailureAudit);
                // at least we tried to clean up
            }

            return !status;
        }
[/code]

Reply with quote

Advertisement

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

Re: Error while downloading.

Ahsan wrote:

But when I download the file then it is not downloaded successfully and file name is also changed.
What does it mean "not successfully". How is the file changed?

Please post a full log file showing the problem.

To generate log file, enable logging, log in to your server and do the operation and only the operation that causes the error. For posting extensive logs you may use pastebin or similar application. 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 may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.

Reply with quote

Ahsan
Guest

Re: Error while downloading.

According to log, The file is downloaded successfully but when I do checksome to validate the data using a hash algorithm(SHA512Managed). The validation is false. I do not know, why it happens? Can you please tell me what should I do ?

<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="username@hostname" start="2011-01-13T11:29:30.341Z">
  <download>
    <filename value="/entitlement/fwis.xml" />
    <destination value="C:\Ahsan_Test\fwis.xml" />
    <result success="true" />
  </download>
  <download>
    <filename value="/entitlement/fwis.xml.sha512" />
    <destination value="C:\Ahsan_Test\fwis.xml.sha512" />
    <result success="true" />
  </download>
</session>

Reply with quote

Ahsan
Guest

Re: Error while downloading.

I am using winscp.com. Basically, My application is winform based and language is C#.net. Please suggest what should i do?

Ahsan

Reply with quote

Advertisement

Ahsan
Guest

Re: Error while downloading.

Yes. I was using ASCII mode. I have changed the mode from ACII to Binary. Now problem is i am not able to download the file. Here are my arguments which i pass to winscp.
 _with2.WriteLine("option batch abort");
            _with2.WriteLine("option confirm on");

            //Open the session.
            _with2.WriteLine(" open " + comboProtocol.Text.Trim() + "://" + txtUsername.Text.Trim() + "@" + txtHostname.Text.Trim() + ":" + int.Parse(txtPort.Text.Trim()) + " -privatekey=\"" + txtPulicKeyFile.Text.Trim() + "\"");
            _with2.WriteLine("cd " + txtRemoteDir.Text);
            
            //set Transfer mode ASCII to Binary
            _with2.Write("option transfer binary");
            
            //Download the file and hash data file 
            _with2.WriteLine("get \"" + txtDownloadFile.Text + "\" \"" + txtLocalDir.Text + "\"");
            _with2.WriteLine("get \"" + txtDownloadFile.Text + ".sha512\" \"" + txtLocalDir.Text + "\"");
            _with2.Close();

please verify my setting either it is ok for download the file and its checksum file.

[quote="prikryl"]Aren't you using ASCII transfer mode?[/quote[/code]

Reply with quote

Vivek
Guest

Getting error while downoading file using winscp

Hi,

I am geeting following error message while downloading file through winscp. I am calling winscp through .Net code.

winscp> get LOANS\LOANS_082011_Data_163275__April_July11_35219.xls D:\PAYROLL\LOANS\LOANS_082011_Data_163275__April_July11_35219.xls
Can't get attributes of file 'LOANS\LOANS_082011_Data_163275__April_July11_35219.xls'.
No such file or directory.
Error code: 2
Error message from server: No such file
Request code: 7
winscp> close

Reply with quote

Advertisement

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

Re: Getting error while downoading file using winscp

Vivek wrote:

Hi,

I am geeting following error message while downloading file through winscp. I am calling winscp through .Net code.

winscp> get LOANS\LOANS_082011_Data_163275__April_July11_35219.xls D:\PAYROLL\LOANS\LOANS_082011_Data_163275__April_July11_35219.xls
Can't get attributes of file 'LOANS\LOANS_082011_Data_163275__April_July11_35219.xls'.
No such file or directory.
Error code: 2
Error message from server: No such file
Request code: 7
winscp> close
My first hint is to use forward slashes for remote path:
LOANS/LOANS_082011_Data_163275__April_July11_35219.xls

Reply with quote

Aswini
Guest

Winscp Automation Problem

Hi,
I have automated the File downloading using C#.net 2005. I have created separate solution for downloading from different site. So, it creates multiple winscp.com process in Task manager. I have a button to Start and stop the downloading. I want to close the appropriate winscp from the list if i click on stop button for particular site. How can i do that.

Reply with quote

Aswini
Joined:
Posts:
4
Location:
Chennai

Got WinSCP.com-Application Error

Hi,
Thanks for your reply Mr.Prikryl

Now I got New error While Synchronizing the folder from remote. I have synchronized from 4 different site. So there is four different applications that are running separately. I have to run these processes simultaneously. While running 4 application, the files are sync in good way.

But it throws the error, like "The application failed to initialize properly.(0xc0000142). Click OK to terminate the application".

If i click, OK means it closes all downloads. Please help me to clear this issue...

I want to run the download function without stopping. It runs continuously, because any time a new file is added in remote folder, so it always keep on checking the remote that there is any new file or folder is created.i want to check the folder continuously. I won't stop the download processes, it always in running mode.

The only problem is that the above error is thrown always. If i click, the OK button it stops all sync processes.
Description: I have used the following code

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Got WinSCP.com-Application Error

Sorry, I'm not sure I understand under what circumstances the error appears. Also error is for WinSCP or your application?

Reply with quote

Aswini
Joined:
Posts:
4
Location:
Chennai

Re: Got WinSCP.com-Application Error

Hi,

Thanks for the reply.

I'm also not sure, but the title of the error message box, shows winSCP.com - application error.

But that error did not come, when i run in my local machine. But the error occurs only on server machine.

The server machine is windows 2008 server, 32 bit system - sp1

Reply with quote

Advertisement

Aswini
Joined:
Posts:
4
Location:
Chennai

Re: Winscp Automation Problem

Hi,
Now the problem is solved me. It is the problem of server. Our Administrator had some changes on that machine, now its going fine.

Please, help me on other problem. I have sync the folder from 4 different FTP sites simultaneously. So there are 4 processes of winSCP.exe in task manager.

My problem is, I have 4 buttons for that above 4 different sites. Each have start and stop options. For example, I have Medlite, Alpha, QT and Direct buttons. If I clicked on Medlite, it starts the sync process from their site. If i clicked on Alpha, it start the sync process from their FTP site and so on.

If I stop the sync of Medlite, it should be stops the medlite sync process only not for other.

I have tried, by creating new winscp.com and give the input like,

Terminate session myusername@MyFTPSite.

But it returns, no session like this.

How can i differentiate from four different process of winscp.com.

Reply with quote

martin
Site Admin
martin avatar

Re: Winscp Automation Problem

As I wrote before, to stop syncing in a middle, you can only terminate the process. As you have for separate processes, I do not see a reason to distinguish the session. Just kill the respective process.

Reply with quote

pattyengr
Joined:
Posts:
5

Special characters getting replaced

hi..I am using winscp to transfer file to server.When sending the file the name of the file which contains special characters are getting replaced with underscores (_).

Any specific reason for this ?

the file body also contains those characters but they are not getting replaced...

Reply with quote

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

Re: Special characters getting replaced

pattyengr wrote:

hi..I am using winscp to transfer file to server.When sending the file the name of the file which contains special characters are getting replaced with underscores (_).

Any specific reason for this ?

the file body also contains those characters but they are not getting replaced...
Duplicate post.

Reply with quote

Advertisement

You can post new topics in this forum