2015-04-05 172 views
-1

我有一个程序根据文件的名称生成一个CSV文件,它必须被压缩。并通过FTP发送到不同的位置通过FTP发送文件

我可以请你的专家建议如何继续使cmd文件动态地接受文件名吗?以及如何使用FTP从我的程序CMD

输出文件:TESTING_OUTPUT.csv在d:\ testingfolder \

输入文件名CMD文件:TESTING_OUTPUT.csv

输出:TESTING_OUTPUT。 ZIP通过FTP发送到1.123.456用户-scott pwd -tiger

如果我能够制作一个CMD文件,那么我想从后SQL调用CMD文件作为调用d:\ TESTINGFOLDER \ FTP.cmd TESTING_OUTPUT .csv

你能帮我做吗CMD?

+0

你到目前为止试过了什么? Google上有很多关于如何通过命令行FTP文件的例子。我们不太适合你的代码(好吧,有人可能,但他们真的不应该),但我们很乐意纠正你现有代码中的任何错误。还有什么意思是“动态接受文件名?” – SomethingDark 2015-04-05 03:16:17

+0

嗨, 我从来没有做过的cmd文件。我是一个数据软件安装专业人员,而不是编码人员。 – 2015-04-05 04:09:37

+0

动态接受文件名我的意思是 调用cmdfilehere inputfilenamehere.csv – 2015-04-05 04:13:10

回答

1

%1是批量命令行参数。

所以使一批与这些线

Echo %1 
Echo %2 

然后请在命令提示符下

nameofbatch.bat Parameter1 "Parameter 2" 

类型ftp /?有关FTP的帮助。使用ftp -s:script来执行一系列ftp命令。键入ftp,然后键入?获取脚本中命令的帮助。

您可以通过批量动态生成脚本来指定不同的文件名。 %1将具有在命令行中指定的名称。

echo open ftp.microsoft.com >ftp.script 
echo. >>ftp.script 
echo user anonymous >>ftp.script 
echo [email protected] >>ftp.script 
echo ls >>ftp.script 
echo get softlib\%1 >>ftp.script 
ftp -s:ftp.script 

所以运行上面的批处理像这样

nameofbatfile.bat readme.txt 

你应该在命令提示符窗口中文件夹中的readme.txt文件。

下面是关于命令提示符的更多信息。查看报价条目。

& seperates commands on a line. 

&& executes this command only if previous command's errorlevel is 0. 

|| (not used above) executes this command only if previous command's errorlevel is NOT 0 

> output to a file 

>> append output to a file 

< input from a file 

| output of one command into the input of another command 

^ escapes any of the above, including itself, if needed to be passed to a program 

" parameters with spaces must be enclosed in quotes 

+ used with copy to concatinate files. E.G. copy file1+file2 newfile 

, used with copy to indicate missing parameters. This updates the files modified date. E.G. copy /b file1,, 

%variablename% a inbuilt or user set environmental variable 

!variablename! a user set environmental variable expanded at execution time, turned with SelLocal EnableDelayedExpansion command 

%<number> (%1) the nth command line parameter passed to a batch file. %0 is the batchfile's name. 

%* (%*) the entire command line. 

%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. Single % sign at command prompt and double % sign in a batch file. 
+0

请参阅?我说有人会回答这个问题,尽管事实是脱离主题,因此不值得回答。 – SomethingDark 2015-04-05 12:46:24