Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default FTP using CMD via VBA

Hi friends,

I am using below code for FTP using vbscript.

Please help me to do same task via VBA.

SystemUtil.run "cmd.exe"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type "cd\"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type "ftp"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type "open mvsftp"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
wait 1
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type usrID "
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type Password
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type "get"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type "'"&dataset& "'"
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type filePath
Window("micclass:=Window","nativeclass:=ConsoleWin dowClass").Type micReturn


Thanks & Regards

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default FTP using CMD via VBA

sachin ahuja wrote:

I am using below code for FTP using vbscript.

Please help me to do same task via VBA.


It depends on what you actually want to do. If you want to specifically
automate ftp, the best way is to use what amounts to a batch file:

'Untested air code...
bakdir$ = CurDir$
ChDir "\"
ftpf = FreeFile
Open "ftpcmds.tmp" For Output As ftpf
Print #ftpf, "open mvsftp"
Print #ftpf, usrID & "
'No need to explicitly wait; ftp will worry about such things for you.
Print #ftpf, Password
Print #ftpf, "get"
Print #ftpf, "'" & dataset & "'"
Print #ftpf, filePath
'At this point, you may want to add an explicit exit to the batch:
'Print #ftpf, "bye"
Close ftpf&
Shell "ftp -s:ftpcmds.tmp"
ChDir bakdir$

If you just need to grab files from an ftp server, you should be able to
connect to it via code and grab your files directly. I'm sure there are
plenty of examples for doing that on the www; Google is your friend.

--
You can't turn the volume down on beating a hooker with a baseball bat.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default FTP using CMD via VBA

I wrote:

Close ftpf&


Damn, missed one. Change "ftpf&" to "ftpf" in the above line.

--
I take myself entirely too seriously.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default FTP using CMD via VBA

I am getting an error:

Run-time error '75' :
Path/File access error

at line :
Open "ftpcmds.tmp" For Output As ftpf

Please help me to resolve this problem.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default FTP using CMD via VBA

sachin ahuja wrote:

I am getting an error:

Run-time error '75' :
Path/File access error

at line :
Open "ftpcmds.tmp" For Output As ftpf

Please help me to resolve this problem.


You probably don't have write access to the root directory. Change the code
to this:

bakdir$ = CurDir$
ChDir "\"
tmpFile = Environ$("TEMP") & "\ftpcmds.tmp"
ftpf = FreeFile
Open tmpFile For Output As ftpf
Print #ftpf, "open mvsftp"
Print #ftpf, usrID & "
'No need to explicitly wait; ftp will worry about such things for you.
Print #ftpf, Password
Print #ftpf, "get"
Print #ftpf, "'" & dataset & "'"
Print #ftpf, filePath
'Without an exit, ftp will not automatically close.
'Print #ftpf, "bye"
Close ftpf
Shell "ftp -s:" & tmpFile
ChDir bakdir$

Note that I haven't tested your ftp script, *just* the VBA code.

--
Did the writers suffer a massive collective amnesia attack?


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default FTP using CMD via VBA

Thanks Auric,
Its working fine now.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"