PowerShell raw FTP
I am looking to use FTP to write a mainframe jobstream. To do that, I can connect to the mainframe via FTP and run these commands:
QUOTE TYPE E
QUOTE SITE FILETYPE=JES
PUT myjob.jcl
So, how would I do this in PowerShell? I have read plenty on standard FTP transfer开发者_运维知识库s, but I haven't seen anything about customizing the calls for prep.
Thanks for reading.
EDIT
Here is the solution I came up with, per the answer here and this article:
@echo off
echo user %1> ftpcmd.dat
echo %2>> ftpcmd.dat
echo QUOTE TYPE E>> ftpcmd.dat
echo QUOTE SITE FILETYPE=JES>> ftpcmd.dat
echo put %3>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat %4
del ftpcmd.dat
Usage:
C:\>fileup user123 pa$$word myfile.txt ftp.server.com
Could you use the -s switch for FTP and specify a file that contains your commands to run?
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
Then you can call this in PowerShell as
ftp -s:<myscript> <host>
If you're comfortable with .NET and want to do it programatically, there is a similar question/answer here:
Upload files with FTP using PowerShell
It pretty much goes comes down to using a System.Net.FtpWebRequest
for the job. At first glance it seems fairly straight forward.
精彩评论