Computing.Net > Forums > Programming > Open cmd.exe on remote machine

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Open cmd.exe on remote machine

Reply to Message Icon

Name: Hviezdoslav
Date: April 22, 2009 at 08:28:51 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Greetings,

I am wondering if anybody has any idea on how I might achieve my programming goal. I am FTPing to KCM_Ext server and am trying to run programmatically a batch file to copy a file from that machine's C drive to a path on the machine's E drive.

There is a VB code-behind page on a server named KCM_Int. There is a server named KCM_Ext. The KCM_Ext has a C drive and an E drive.

From the VB code-behind page on KCM_Int, I am FTPing to the other server KCM_Ext.

The KCM_Int server has the ftp file and response.tmp file as well as the VB code-behind. It also has a cmd.exe.

The KCM_Ext has cmd.exe and files.bat. The cmd.exe and files.bat are in the same folder on the C drive as the file that the batch file's code is trying to copy.

So I need not change the directory once I have finished FTPing to KCM_Ext. When I manually open cmd.exe on KCM_Ext, it already is at the directory C:\WINDOWS\system32\LogFiles\W3SVC1649540525 that has the PDF file to be copied by the batch file, the cmd.exe, and the files.bat.

The code in the files.bat is the following:

@ECHO OFF
         copy %1 %2 /v /y
         CLS
         EXIT 

When I go to KCM_Ext, open the cmd.exe, and run the bat file's code using the hard-coded "copy justTesting_files.pdf E:\site\files\files" I can copy the file successfully.

Farther up in the code-behind, the string variables TheFile and pathToWhichToCopyOnKCM_EXT have been given values already (for example, justTesting_files.pdf and E:\site\files\files respectively).

The applicable code in the code-behind has the following lines:

Dim FtpDirectory As String = Request.ServerVariables("APPL_PHYSICAL_PATH") & "ftp\"
Dim my_arDirList As Array = Split(Replace(myCurrentDir, myRoot, ""), "\")
Dim myObjWriter As StreamWriter = New StreamWriter(FtpDirectory & "wwwupload3.ftp")
myObjWriter.WriteLine("open " & TheSite)
myObjWriter.WriteLine(ConfigurationManager.AppSettings.Item("FTP_user"))
myObjWriter.WriteLine(ConfigurationManager.AppSettings.Item("FTP_pass"))


myObjWriter.WriteLine("cmd.exe -s:files.bat " & TheFile.ToString() & " " & pathToWhichToCopyOnKCM_Ext.ToString())


myObjWriter.WriteLine("bye")
myObjWriter.Flush()
myObjWriter.Close()
myObjWriter = Nothing
Dim myStrCMD As String = FtpDirectory & "ftp.exe -s:" & FtpDirectory & "wwwupload3.ftp"
Dim myStrTempFile As String = FtpDirectory & "response3.tmp" 
myStrCMD = FtpDirectory & "cmd.exe /c " & myStrCMD & " > " & myStrTempFile
Dim myScript As Object = CreateObject("Wscript.Shell")
Call myScript.Run(myStrCMD, 0, True)
myScript = Nothing

I get no error but the batch file's code is not copying the justTesting_file.pdf to the E drive's path on KCM_Ext (E:\site\files\files). I even tried in the code-behind to hard-code rather than use the variables TheFile and pathToWhichToCopyOnKCM_Ext, but it made no difference.

If I am on KCM_Ext and open cmd.exe and type "copy justTesting_files.pdf E:\site\files\files /v /y" I can copy successfully of course the file.

So I think that in the VB code-behind page I am not coding correctly to use cmd.exe on the remote KCM_Ext server to run its batch file and/or to pass correctly the parameters to run the batch file.

I have tried various lines of code from the code-behind to run cmd.exe to run the batch file passing it parameters to do the copying of the file. I get no error but the file is not copied successfully.

I know I am FTPing to KCM_Ext successfully because I tried in the code-behind the following line of code and the response3.tmp file on KCM_Int shows the files within KCM_Ext's C:\Windows\System32\LogFiles\W3SVC1649540525:

myObjWriter.WriteLine("dir")

Also, if I use the following line of code I can rename successfully the file after FTPing to KCM_Ext:

myObjWriter.WriteLine("rename " & TheFile & " " & "justTesting_files_NewName.pdf") 

From my research, it seems that I cannot use FTP once the code-behind arrives at KCM_Ext because I need to copy to a different drive and not just to another path on the same drive. From my research, it seems that FTP commands cannot execute cmd.exe or a batch file since FTP was created to transfer files basically. I of course might not understand correctly though and maybe I am mistaken.

Here are only some of the various versions of the line of code that I have tried to use (in place of the line of code in the above code that I separated with a space above and below it):

myObjWriter.WriteLine("-s:" & "files.bat" & " " & TheFile & " " & pathToWhichToCopyOnKCMExtWeb02) 

or

myObjWriter.WriteLine("files.bat" & " " & TheFile & " " & pathToWhichToCopyOnKCMExtWeb02) 

or

myObjWriter.WriteLine("cmd.exe /c files.bat" & " " & TheFile & " " & pathToWhichToCopyOnKCMExtWeb02) 

or

myObjWriter.WriteLine("echo cmd.exe /c >> files.bat" & " " & TheFile & " " & pathToWhichToCopyOnKCMExtWeb02)

or

myObjWriter.WriteLine("START cmd.exe CALL files.bat justTesting_files.pdf E:\site\files\files") 

If anybody has any idea what I am doing wrong, I would be very grateful if he or she would please be so kind as to let me know.

I thank you in advance.



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Open cmd.exe on remote machine

How to open cmd.exe in VB6 www.computing.net/answers/programming/how-to-open-cmdexe-in-vb6/7943.html

cmd.exe alternative from JPSoft? www.computing.net/answers/programming/cmdexe-alternative-from-jpsoft/17245.html

Perl: Open a file on remote system www.computing.net/answers/programming/perl-open-a-file-on-remote-system/5870.html