2015-04-05 205 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