用于在没有-R的FTP服务器上进行递归目录列表的Bash脚本

时间:2021-07-19 00:05:08

There are multiple folders with subfolders and image files on the FTP server. The -R is disabled. I need to dump the recursive directory listing with the path name in a text file. The logic I have till now is that, traverse in each folder, check the folder name if it consists of '.' to verify it as a file or a folder, if its a folder, go in and check for subfolders or files and list them. Since I cannot go with the -R, I have to go with a function to perform traverse each folder.

FTP服务器上有多个包含子文件夹和图像文件的文件夹。 -R已禁用。我需要在文本文件中转储带有路径名的递归目录列表。我到现在的逻辑是,遍历每个文件夹,检查文件夹名称是否包含'。'要将其验证为文件或文件夹,如果是文件夹,请进入并检查子文件夹或文件并列出它们。由于我不能使用-R,我必须使用函数来遍历每个文件夹。

#!/bin/sh  
ftp_host='1.1.1.1'  
userName='uName'  
ftp -in <<EOF  
open $ftp_host  
user $userName  
    recurList() {
    path=`pwd`
    level=()
    for entry in `ls`
    do
            `cwd`
close
bye
EOF  

I am stuck with the argument for the for loop!

我坚持使用for循环的参数!

1 个解决方案

#1


Sorry to see you didn't get any replies yet. I think the reason may be that Bash isn't a good way to solve this problem, since it requires interacting with the FTP client, i.e. sending commands and reading responses. Bash is no good at that sort of thing. So there is no easy answer other than "don't use Bash".

很抱歉看到您还没有得到任何回复。我认为原因可能是Bash不是解决这个问题的好方法,因为它需要与FTP客户端交互,即发送命令和读取响应。 Bash并不擅长这种事情。所以除了“不要使用Bash”之外没有简单的答案。

I suggest you look at two other tools.

我建议你看看另外两个工具。

Firstly, you may be able to get the information you want using http://curlftpfs.sourceforge.net/. If you mount the FTP server using curlftpfs, then you can use the find command to dump the directory structure. This is the easiest option... if it works!

首先,您可以使用http://curlftpfs.sourceforge.net/获取所需信息。如果使用curlftpfs挂载FTP服务器,则可以使用find命令转储目录结构。这是最简单的选择......如果它有效!

Alternatively, you could write a program using Python with the ftplib module: https://docs.python.org/2/library/ftplib.html. The module allows you to interact with the FTP server through API calls.

或者,您可以使用带有ftplib模块的Python编写程序:https://docs.python.org/2/library/ftplib.html。该模块允许您通过API调用与FTP服务器进行交互。

#1


Sorry to see you didn't get any replies yet. I think the reason may be that Bash isn't a good way to solve this problem, since it requires interacting with the FTP client, i.e. sending commands and reading responses. Bash is no good at that sort of thing. So there is no easy answer other than "don't use Bash".

很抱歉看到您还没有得到任何回复。我认为原因可能是Bash不是解决这个问题的好方法,因为它需要与FTP客户端交互,即发送命令和读取响应。 Bash并不擅长这种事情。所以除了“不要使用Bash”之外没有简单的答案。

I suggest you look at two other tools.

我建议你看看另外两个工具。

Firstly, you may be able to get the information you want using http://curlftpfs.sourceforge.net/. If you mount the FTP server using curlftpfs, then you can use the find command to dump the directory structure. This is the easiest option... if it works!

首先,您可以使用http://curlftpfs.sourceforge.net/获取所需信息。如果使用curlftpfs挂载FTP服务器,则可以使用find命令转储目录结构。这是最简单的选择......如果它有效!

Alternatively, you could write a program using Python with the ftplib module: https://docs.python.org/2/library/ftplib.html. The module allows you to interact with the FTP server through API calls.

或者,您可以使用带有ftplib模块的Python编写程序:https://docs.python.org/2/library/ftplib.html。该模块允许您通过API调用与FTP服务器进行交互。