English 中文(简体)
在Windows批处理文件中控制psftp
原标题:
  • 时间:2009-03-29 06:24:14
  •  标签:

我该如何编写一个批处理文件来控制psftp,但文件名是动态的?总体来说,我试图转换一个视频文件,然后上传到我的Apple TV。这是我的代码,它通常可以工作,但命令不能控制psftp,psftp只是等待用户输入:

echo Convert and Upload to Apple TV file Called %1.mkv

ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi

psftp frontrow@192.168.1.50 -pw aaa
cd downloads/boxee
put %1.avi
quit

I know with the -b flag psftp can call it s own batch file, but I don t know how to get the %1 argument to it. I ve seen solutions where a text file is redirected to psftp, but that suffers from the same problem. Also, I d prefer to have just one file, but having to call a second file would be alright too.

最佳回答

最终我从主要的批处理文件中创建了一个新的批处理文件,然后告诉psftp使用它:

echo cd downloads/boxee > psftp.bat
echo put "%1.avi" >> psftp.bat
echo quit >> psftp.bat

psftp frontrow@192.168.1.50 -pw aaa -b psftp.bat
问题回答

指定包含批处理命令的文件

In normal operation, PSFTP is an interactive program which displays a command line and accepts commands from the keyboard.

如果您需要使用PSFTP执行自动化任务,则可能更倾向于预先指定一组命令并自动执行它们。 -b选项允许您执行此操作。您可以将其与包含批处理命令的文件名一起使用。例如,您可以创建一个名为myscript.scr的文件,其中包含像这样的行:

cd /home/ftp/users/jeff
del jam-old.tar.gz
ren jam.tar.gz jam-old.tar.gz
put jam.tar.gz
chmod a+r jam.tar.gz
quit

然后你可以通过输入命令来运行脚本

psftp user@hostname -b myscript.scr

感谢http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html#6.1.3

All in one file:

@echo off
echo Convert and Upload to Apple TV file Called %1.mkv
ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
(
echo cd downloads/boxee
echo put %1.avi
echo quit
) | psftp frontrow@192.168.1.50 -pw aaa -bc

If we need the precise port number:

psftp frontrow@192.168.1.50 -P 222 -pw aaa -bc

为什么不使用 Windows 自带的 FTP 命令?

你需要编写一个脚本来上传文件:

open 192.168.1.50
user
frontrow aaa
put file.avi
quit

然后调用ftp -s:MyScript

你需要使用echo和 >> 重定向器为每个文件生成脚本。

我正在努力运行一个简单的批处理文件/脚本,让最终用户将她刚刚编辑的文件上传到安全的FTP站点。

Using This Script:

cd /outgoing
put Examplefile.txt
# chmod a+r Examplefile.txt
# ren Examplefile.txt Exam.ted
# rm Examplefile.txt
quit

并从标准的Windows命令提示符中运行PuTTY s sftp命令:

psftp user@ftp.address.com -pw password -b testscript.scr

I was able to quickly and (more importantly!!) easily upload a file from the company I am doing work for to a company we needed to transact business with. You can also see I am ready to rename the file if needed (ren) or delete a file if needed (rm). The hash symbol (#) sets the lines as remark lines.

这使我能够在Windows中创建完整的批处理文件,最终用户可以简单地点击它来上传她生成的文件。这比我在网络上找到的其他“口味”的sftp要简单得多,而我已经使用和信任PuTTY几十年了。

如果您的FTP操作仅涉及上传单个文件,可以使用pscp

echo Convert and Upload to Apple TV file Called %1.mkv

ffmpeg -i %1.mkv -vcodec mpeg4 -acodec ac3 -ab 384k -sameq -s hd720 -t 60 %1.avi
pscp -pw aaa -sftp %1.avi frontrow@192.168.1.50:/downloads/boxee




相关问题
热门标签