Note that there are some explanatory texts on larger screens.

plurals
  1. POFTP:Upload file to FTP and verify
    primarykey
    data
    text
    <p>I am using VBS to </p> <ol> <li>Upload a file to FTP </li> <li>Verify the upload process</li> </ol> <p>I am using the method which creates a text file, fills it with the appropriate command and then execute it using ftp.exe in windows. </p> <pre><code> FTPCommand = "%systemroot%\System32\ftp.exe -s:session.txt" FTPCommand = objshell.ExpandEnvironmentStrings(FTPCommand) objshell.Run FTPCommand,, vbTrue fso.DeleteFile "session.txt", vbTrue </code></pre> <p>Part 1 is done using this code: </p> <pre><code> Set SessionFile = fso.OpenTextFile("session.txt", 2, vbTrue) With SessionFile .WriteLine "open abcd.com" .WriteLine "username" .WriteLine "pwd" .WriteLine "cd /Test/Test1" .WriteLine "put """ &amp; File.Path &amp; """" .WriteLine "quit" .Close End With FTPCommand = "%systemroot%\System32\ftp.exe -s:session.txt" FTPCommand = objshell.ExpandEnvironmentStrings(FTPCommand) objshell.Run FTPCommand,, vbTrue fso.DeleteFile "session.txt", vbTrue </code></pre> <p>And Part 2 is done using this code: </p> <pre><code> Set SessionFile = fso.OpenTextFile("session.txt", 2, vbTrue) With SessionFile .WriteLine "open abcd.com" .WriteLine "username" .WriteLine "pwd" .WriteLine "cd /Test/Test1" .WriteLine "ls" .WriteLine "close" .WriteLine "bye" .Close End With FTPCommand = "%systemroot%\System32\ftp.exe -s:session.txt" FTPCommand = objshell.ExpandEnvironmentStrings(FTPCommand) set ObjExec=objshell.exec(FTPCommand) DO WHILE ObjExec.status=0 : wscript.sleep 50 : LOOP StrTemp=ObjExec.stdout.readall IF instr(1,StrTemp,File.Name,1)&lt;&gt;0 THEN AlertMessage = AlertMessage &amp; vbTab &amp; "STATUS: UPLOAD SUCCESSFUL" &amp; vbCrLf &amp; vbCrLf ELSE AlertMessage = AlertMessage &amp; vbTab &amp; "STATUS: UPLOAD FAILED" &amp; vbCrLf &amp; vbCrLf END IF fso.DeleteFile "session.txt", vbTrue </code></pre> <p>The problem is that (in part 2 code) the code after </p> <pre><code> DO WHILE ObjExec.status=0 : wscript.sleep 50 : LOOP </code></pre> <p>never returns.So the file gets uploaded but the code to check the status never returns.<br> The session.txt file does not get delete and when I execute the command </p> <pre><code>%systemroot%\System32\ftp.exe -s:session.txt </code></pre> <p>manually it indeed shows me the list of files (because of ls command). </p> <p>I have 3 questions: </p> <ol> <li>Why it does not return. Where to start debugging from?</li> <li>Is there anyway I can upload the file and check its status(maybe by the error code returned by the ftp command after the "put" command).</li> <li>Is there is an incorrect directory specified in the code to upload file, the cd command fails and it incorrectly "puts" the file in the root folder. same goes for the code checking the file upload. So even if the directory specified in wrong, the program returns it as successful</li> </ol> <p><strong>Edit 1:</strong> I tried it using </p> <pre><code>.WriteLine "cd /Test" </code></pre> <p>and it worked. Is that directory switching (two folders deep)causing the problem ? </p> <p><strong>Edit 2:</strong> I ran the ls command manually and it ran fine. The output is: </p> <pre><code>226 Transfer complete. ftp: 586493 bytes received in 4.28Seconds 137.00Kbytes/sec. </code></pre> <p>Is 586493 bytes too much for this ? </p> <p>I believe the problem may be:<br> 1)The large no of files returned by LS command.<br> 2)The directory structure I am accessing.</p> <p><strong>Edit:3</strong> From this <a href="http://support.microsoft.com/kb/960246" rel="nofollow">microsoft</a> website it looks like the above point 1 is the culprit: </p> <blockquote> <p>A console application's StdOut and StdErr streams share the same internal 4KB buffer. In addition, the WshScriptExec object only provides synchronous read operations on these streams. Synchronous read operations introduce a dependency between the calling script reading from these streams and the child process writing to those streams, which can result in deadlock conditions.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload