How do I get error codes or output from the sftp command within a batch file?

using sftp in a batch file and would like to be able to get error codes for the connection I make to a server from the commands output.
alphonsobasemoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveGTRCommented:
You could do this:

sftp www.site.com >errors.txt

If you want to check the error code then you could examine %errorlevel%

sftp www.site.com >errors.txt

echo sftp returned %errorlevel%

You may be able to glean more insight into the workings of sftp by accessing the command line help:

sftp ?

Good Luck,
Steve
0
Jeff DarlingDeveloper AnalystCommented:
What sftp client program are you using?  

I don't think any of the Windows operating systems come with a sftp client, only ftp.

The %errorlevel% as described by SteveGTR should be what you are looking for.

0
alphonsobasemoreAuthor Commented:
I'm working in MS DOS!
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

alphonsobasemoreAuthor Commented:
I'm using an sftp client!  The network I'm using allows both ftp and sftp usage.
0
SteveGTRCommented:
Did you try any of my suggestions?
0
alphonsobasemoreAuthor Commented:
Hi SteveGTR,

     I just tried the sftp www.site.com >errors.txt technique and also I checked the errorlevel variable as needed!  Seems that the errors.txt file doesn't have anything inside of it when it is overwritten.  Also, the errorlevel variable doesn't seem have any value but 0.
0
SteveGTRCommented:
So if you say:

sftp www.someinvalidsite.com >errors.txt

What is displayed at the MS-DOS console?

And nothing is placed in errors.txt?

You could try:

sftp www.someinvalidsite.com 2>errors.txt

What is in errors.txt in this case?

Also, what is output when you do this:

sftp ?

Please answer those questions and maybe we can get this to work for you.

Thanks :)
0
alphonsobasemoreAuthor Commented:
Hi SteveGTR,

     When I perform the sftp ? command Dos doesn't give me what you expect, but instead it tries to login onto the the ?@? server.  The ?@? format I believe is based on the fact that this sftp client is ran by saying

sftp <username>@<servername> , which allows user username to login into the server servername.

Also, when I run the sftp www.someinvalidsite.com 2>errors.txt I get another prompt without any output and then dos comes up with the same window to login into the server www.someinvalidsite.com.

Thanks,

Alphonso
0
Jeff DarlingDeveloper AnalystCommented:

Can you supply the version of MS DOS and SFTP that you are using?

The experts will be able to assist you better given this information.

You can find out the version of MS DOS by typing VER at the command line.

You might be able to find the Version of your sftp program by typing sftp /? or just sftp by itself on the command line.  It is most likely a 3rd part sftp program.  If you can provide the link for the vendor of this program that would also be helpful.


0
alphonsobasemoreAuthor Commented:
The MS DOS is: version is 5.1.2600 for MS Windows XP.

At this point I can't get access to the sftp server due to network issues to get the version, but I can get the versioning information for the ftp protocol.  The ftp version is 4.1 and I'd imagine that the sftp protocol wouldn't be any further away from that version.
0
SteveGTRCommented:
Yes, try the following:

sftp /?

or

sftp -?

Post the results.

Also, if you fo this:

sftp www.someinvalidsite.com 2>errors.txt

Enter a bogus user name and password.

What's in errors.txt?
0
alphonsobasemoreAuthor Commented:
Oh on the sftp version.  The only thing I can tell you is that when I do the command sftp by itself I get another command prompt with the windown title:     sftp

and then inside the window the program gives the syntax of the command like so:
-----------------------------------------------------------------------------------------------------

usage: sftp [-b batchfile] [-p port]  [-i identityfile] [-o Cipher]  [user@]host[:file [file]]

press ENTER key to quit

-----------------------------------------------------------------------------------------------------

I imagine you guys might be fimiliar with an sftp client that gives it's syntax within a seperate dos prompt window since most sftp clients run like ftp inside the same prompt right?
0
alphonsobasemoreAuthor Commented:
Hi SteveGTR,

when I run sftp -? or sftp /? I get a seperate dos prompt with a title of sftp -? or sftp /? based on the command I ran and the syntax of the command printed out twice like so:

usage: sftp [-b batchfile] [-p port]  [-i identityfile] [-o Cipher]  [user@]host[:file [file]]

usage: sftp [-b batchfile] [-p port]  [-i identityfile] [-o Cipher]  [user@]host[:file [file]]

press ENTER key to quit

Also, when I do the sftp www.someinvalidesite.com 2>errors.txt command I get nothing in errors.txt. I think this is because of the fact that this sftp client doesn't seem to print anything out at the original command prompt.  The only thing the command does is distribute focus to the new dos prompt the command opens for logging into the sftp server.
0
SteveGTRCommented:
Do you know who makes this version of sftp?

When you type sftp at the command prompt can you identify the program that it is running?

You might be able to do this by doing the following:

c:
cd \
dir /s sftp.*

What does the dir command find?
0
alphonsobasemoreAuthor Commented:
Great idea SteveGTR!

     I just ran the dir /s sftp.* command in the C drive and the version of the sftp is:

          8.0.2119.0 and the Attachmate Corporation is the 3rd party company that created the protocol.

     There also is a sftp.vbs file associated with sftp, but I don't think that file is needed necessarily to figure out this issue or is it really important to the issue.  The fact that Attachmate created the sftp version should be enough right?
0
SteveGTRCommented:
Well the VBS file is what is running the processing. Can you post the contents of the sftp.vbs file?
0
alphonsobasemoreAuthor Commented:
Ya,

here it is:

# $language = "VBScript"
# $interface = "1.0"

' Example script that starts SecureNetTerm, connects to the active profile,
' then waits for a $ prompt.  When it is received, it tests the SFTP commands.

' This assumes an SSH style connection in which no userid or password is
' required to be entered on the command line.

' You should place a very large (4-8MB) file in the host /tmp directory,
' with a name of remote.fil which will be used by this test.

' Globals
dim dir
dim snt

Sub StartSNT
  ' Request to handle errors ourselves so we can handle possible failure
  ' of GetObject() to connect to SecureNetTerm...
  '
  On Error Resume Next
  ' Gets an instance of SecureNetTerm if it is already running
  Set snt = GetObject(,"SecureNetTerm.Document")
  If TypeName(snt) <> "Document" Then
    ' It wasn't already running so start it running.
    Set snt = CreateObject("SecureNetTerm.Document")
  End If
End Sub

Sub Main()
 StartSNT()
 snt.WindowState = 1 'Normal (SW_SHOW)
 If snt.Connected <> TRUE Then
      If snt.Connect("Active") <> TRUE Then
           Exit Sub
      End If
      If snt.WaitForString("$",15) <> TRUE Then
           Exit Sub
      End If
 End If
 ret = snt.SFTP_OpenConnection()
 if ret = TRUE Then
      dir = snt.SFTP_GetCurrentDirectory()
      snt.StatusLine "SFTP Directory = " + dir
      ret = snt.SFTP_SetCurrentDirectory("/tmp")
      if ret = TRUE Then
           ' Make sure test directory/files are not present
           snt.SFTP_DeleteFile("sntData/remote2.fil")
           snt.SFTP_RemoveDirectory("sntData")
           ret = snt.SFTP_GetFile("remote.fil","local.fil")
           if ret = TRUE Then
                dir = snt.SFTP_GetCurrentDirectory()
                snt.StatusLine "SFTP Directory = " + dir
                ret = snt.SFTP_CreateDirectory("sntData")
                if ret = TRUE Then
                     ret = snt.SFTP_PutFile("local.fil","sntData/remote1.fil")
                     if ret = TRUE Then
                          ret = snt.SFTP_RenameFile("sntData/remote1.fil","sntData/remote2.fil")
                          if ret = TRUE Then
                               ret = snt.SFTP_ChMod("sntData/remote2.fil","644")
                               if ret = TRUE Then
                                    ret = snt.SFTP_GetFile("sntData/remote2.fil","local2.fil")
                                    if ret = TRUE Then
                                         ret = snt.SFTP_DeleteFile("sntData/remote2.fil")
                                         if ret = TRUE Then
                                              ret = snt.SFTP_RemoveDirectory("sntData")
                                         End If
                                    End If
                               End If
                          End If
                     End If
                End If
           End If
      End If
 snt.SFTP_CloseConnection()
 snt.StatusLine ""
 End If
End Sub
0
SteveGTRCommented:
Looks like this script drives InterSoft Internation, Inc's SecureNetTerm.

I'm not familiar with this software and don't have the time to learn it. Here's a link to the PDF manual.

http://www.securenetterm.com/pub/SecureNetTerm.pdf

Good Luck,
Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alphonsobasemoreAuthor Commented:
Thanx for the help! I'll post my results.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.