Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:00:20+00:00 2026-06-13T09:00:20+00:00

I am using VBS to Upload a file to FTP Verify the upload process

  • 0

I am using VBS to

  1. Upload a file to FTP
  2. Verify the upload process

I am using the method which creates a text file, fills it with the appropriate command and then execute it using http://ftp.exe in windows.

            FTPCommand = "%systemroot%\System32\ftp.exe -s:session.txt"
            FTPCommand = objshell.ExpandEnvironmentStrings(FTPCommand)
            objshell.Run FTPCommand,, vbTrue
            fso.DeleteFile "session.txt", vbTrue

Part 1 is done using this 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 """ & File.Path & """"
                .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

And Part 2 is done using this 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)<>0 THEN
                AlertMessage = AlertMessage & vbTab & "STATUS: UPLOAD SUCCESSFUL" & vbCrLf & vbCrLf
            ELSE
                AlertMessage = AlertMessage & vbTab & "STATUS: UPLOAD FAILED" & vbCrLf & vbCrLf
            END IF
            fso.DeleteFile "session.txt", vbTrue 

The problem is that (in part 2 code) the code after

            DO WHILE ObjExec.status=0 : wscript.sleep 50 : LOOP

never returns.So the file gets uploaded but the code to check the status never returns.
The session.txt file does not get delete and when I execute the command

%systemroot%\System32\ftp.exe -s:session.txt

manually it indeed shows me the list of files (because of ls command).

I have 3 questions:

  1. Why it does not return. Where to start debugging from?
  2. 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).
  3. 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

Edit 1:
I tried it using

.WriteLine "cd /Test"

and it worked. Is that directory switching (two folders deep)causing the problem ?

Edit 2:
I ran the ls command manually and it ran fine. The output is:

226 Transfer complete.
ftp: 586493 bytes received in 4.28Seconds 137.00Kbytes/sec.

Is 586493 bytes too much for this ?

I believe the problem may be:
1)The large no of files returned by LS command.
2)The directory structure I am accessing.

Edit:3
From this microsoft website it looks like the above point 1 is the culprit:

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:00:21+00:00Added an answer on June 13, 2026 at 9:00 am

    I believe the problem is the way you read the stdout from the process. I use this technique succesfully as follows, sorry, I have no time to adapt your script and try it out, so that is up to you.

    The following executes a ping to check if the server is online.

    Function IsOnline(Address) 
      Dim strText 
      IsOnline = False 
      Set oExecObj = oShell.Exec("%comspec% /c ping -a -n 1 -w 20 " & Address) 
      Do While Not oExecObj.StdOut.AtEndOfStream 
        strText = oExecObj.StdOut.ReadAll() 
        If Instr(strText, "Reply from") > 0 Then 
          IsOnline = True 
          Exit Function 
        End If 
      Loop 
    End Function       
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very simple question I am sure. I have a file called ACLReader.vbs which I
I am currently using a VB-Skript, which is used to start a setup.exe file,
I want to run window media player using .vbs file currently i'am running applications
I am using vbscript (.vbs file) to set the values of an excel sheet.
Using the Redis info command, I am able to get all the stats of
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
Using the command line tool, ldapquery, the command is this: ldapsearch -h myldapserver uid=myloginname
I've got a solution which I setup / cleanup using batch files ... -
I'm trying to read xml file from vbs script. Xml is encoded in utf-8
I'm trying to write a VBScript (.vbs) script that uses the WScript.Shell Run() method,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.