控制Windows批处理文件中的psftp

时间:2022-03-18 02:22:20

How do I write a batch file to control psftp, but with a dynamic filename? Overall I'm trying to convert a video file and then upload it to my Apple TV. Here's what I have, it generally works, but the commands don't control psftp, psftp just waits for user input:

如何编写批处理文件来控制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.

我知道-b标志psftp可以调用它自己的批处理文件,但我不知道如何获取它的%1参数。我已经看到了将文本文件重定向到psftp的解决方案,但是遇到了同样的问题。此外,我更喜欢只有一个文件,但不得不调用第二个文件也没关系。

6 个解决方案

#1


I ended up creating a new batch file from the main one that I then told psftp to use:

我最后创建了一个新的批处理文件,然后我告诉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

#2


Specify a file containing batch commands

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

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

在正常操作中,PSFTP是一个交互式程序,它显示命令行并接受来自键盘的命令。

If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.scr containing lines like this:

如果您需要使用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

and then you could run the script by typing

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

psftp user@hostname -b myscript.scr

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

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

#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

#4


Why not use the built in FTP command that comes with windows?

为什么不使用Windows附带的内置FTP命令?

you will need to write a script that will upload the file:

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

open 192.168.1.50
user
frontrow aaa
put file.avi
quit

打开192.168.1.50用户frontrow aaa put file.avi quit

then call ftp -s:MyScript

然后调用ftp -s:MyScript

You will need to generate the script per each file using echo and the >> redirector.

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

#5


If all you're doing with ftp is uploading a single file, you can use pscp.

如果您正在使用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

#6


I was struggling to run a simple batch file/script to have an end user upload a file she had just edited to a secure FTP site.

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

Using This Script:

使用此脚本:

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

and running PuTTY's sftp command from a standard Windows command prompt:

并从标准的Windows命令提示符运行PuTTY的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.

我能够快速地(更重要的是!!)轻松地将我正在工作的公司的文件上传到我们需要与之交易的公司。您还可以看到我已准备好在需要时重命名文件(ren)或删除文件(如果需要)(rm)。哈希符号(#)将行设置为备注行。

This allowed me to create a complete batch file in Windows that the end user could simply click on to upload the files as she generated them. It was MUCH simpler than using some of the other "flavors" of sftp I found on the 'Net and I have used and trusted PuTTY for decades.

这使我能够在Windows中创建一个完整的批处理文件,最终用户只需单击该文件即可在生成文件时上载文件。它比使用我在网上找到的其他一些sftp“风味”简单得多,我已经使用和信任PuTTY几十年了。

#1


I ended up creating a new batch file from the main one that I then told psftp to use:

我最后创建了一个新的批处理文件,然后我告诉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

#2


Specify a file containing batch commands

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

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

在正常操作中,PSFTP是一个交互式程序,它显示命令行并接受来自键盘的命令。

If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.scr containing lines like this:

如果您需要使用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

and then you could run the script by typing

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

psftp user@hostname -b myscript.scr

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

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

#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

#4


Why not use the built in FTP command that comes with windows?

为什么不使用Windows附带的内置FTP命令?

you will need to write a script that will upload the file:

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

open 192.168.1.50
user
frontrow aaa
put file.avi
quit

打开192.168.1.50用户frontrow aaa put file.avi quit

then call ftp -s:MyScript

然后调用ftp -s:MyScript

You will need to generate the script per each file using echo and the >> redirector.

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

#5


If all you're doing with ftp is uploading a single file, you can use pscp.

如果您正在使用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

#6


I was struggling to run a simple batch file/script to have an end user upload a file she had just edited to a secure FTP site.

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

Using This Script:

使用此脚本:

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

and running PuTTY's sftp command from a standard Windows command prompt:

并从标准的Windows命令提示符运行PuTTY的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.

我能够快速地(更重要的是!!)轻松地将我正在工作的公司的文件上传到我们需要与之交易的公司。您还可以看到我已准备好在需要时重命名文件(ren)或删除文件(如果需要)(rm)。哈希符号(#)将行设置为备注行。

This allowed me to create a complete batch file in Windows that the end user could simply click on to upload the files as she generated them. It was MUCH simpler than using some of the other "flavors" of sftp I found on the 'Net and I have used and trusted PuTTY for decades.

这使我能够在Windows中创建一个完整的批处理文件,最终用户只需单击该文件即可在生成文件时上载文件。它比使用我在网上找到的其他一些sftp“风味”简单得多,我已经使用和信任PuTTY几十年了。