Topic "Error while downloading."

Author Message
Ahsan

Guest


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;
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]
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Ahsan

Guest


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 ?

Code:

<?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>
Ahsan

Guest


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

Ahsan
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Aren't you using ASCII transfer mode?
_________________
Martin Prikryl
Ahsan

Guest


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.
Code:
 _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]
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
WriteLine, not Write.
_________________
Martin Prikryl
Ahsan

Guest


Thanks. It is working.. Cheers
prikryl wrote:
WriteLine, not Write.
Vivek

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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
_________________
Martin Prikryl
Aswini

Guest


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
There's no better way apart from killing the process.
_________________
Martin Prikryl
Aswini
[View user's profile]

Joined: 2012-01-07
Posts: 4
Location: Chennai
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.
code.txt (3.95 KB) [Download]

Description: I have used the following code

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Sorry, I'm not sure I understand under what circumstances the error appears. Also error is for WinSCP or your application?
_________________
Martin Prikryl
Aswini
[View user's profile]

Joined: 2012-01-07
Posts: 4
Location: Chennai
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
I have sent you an email.
_________________
Martin Prikryl
Aswini
[View user's profile]

Joined: 2012-01-07
Posts: 4
Location: Chennai
Hi,

I have sent an email to you.
Aswini
[View user's profile]

Joined: 2012-01-07
Posts: 4
Location: Chennai
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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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.
_________________
Martin Prikryl
pattyengr
[View user's profile]

Joined: 2012-06-22
Posts: 5
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...
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License