Window平台和Linux平台下Ftp服务器的区别

在处理Ftp下载的一段程序时, 原来使用Linux下的ftp服务器程序都是正常的, 而换了一个windows平台下的ftp服务器时, 文件下载好像进入了死循环, 一次次的下载同样的文件和目录.

 

最后发现原因是, windows下的ftp服务器在list命令的返回中会包含"."和".."两个子目录, 而在处理子目录列表时没有去掉这两个, 从而导致实际上的重复处理相同目录. 而linux平台下的服务器不会包含这两个子目录, 所以不会有这个问题出现.

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用PyQt5和ftplib库创建一个FTP客户端应用程序。以下是一个示例代码,展示了如何连接到Linux上的FTP服务器,并提供上传和下载文件的功能。 ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QMessageBox from ftplib import FTP class FTPClient(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("FTP Client") self.setGeometry(100, 100, 300, 200) self.btn_upload = QPushButton("Upload", self) self.btn_upload.setGeometry(50, 50, 200, 30) self.btn_upload.clicked.connect(self.uploadFile) self.btn_download = QPushButton("Download", self) self.btn_download.setGeometry(50, 100, 200, 30) self.btn_download.clicked.connect(self.downloadFile) def uploadFile(self): file_path, _ = QFileDialog.getOpenFileName(self, 'Select file to upload', '', 'All Files (*)') if file_path: ftp = FTP('ftp.example.com') # Replace with your FTP server address ftp.login('username', 'password') # Replace with your FTP credentials file_name = file_path.split('/')[-1] try: with open(file_path, 'rb') as file: ftp.storbinary(f'STOR {file_name}', file) QMessageBox.information(self, 'Success', 'File uploaded successfully!') except Exception as e: QMessageBox.critical(self, 'Error', f'Failed to upload file: {str(e)}') ftp.quit() def downloadFile(self): file_name, _ = QFileDialog.getSaveFileName(self, 'Save file', '', 'All Files (*)') if file_name: ftp = FTP('ftp.example.com') # Replace with your FTP server address ftp.login('username', 'password') # Replace with your FTP credentials try: with open(file_name, 'wb') as file: ftp.retrbinary(f'RETR {file_name}', file.write) QMessageBox.information(self, 'Success', 'File downloaded successfully!') except Exception as e: QMessageBox.critical(self, 'Error', f'Failed to download file: {str(e)}') ftp.quit() if __name__ == '__main__': app = QApplication(sys.argv) window = FTPClient() window.show() sys.exit(app.exec_()) ``` 请注意,上述代码中的服务器地址、用户名、密码等需要替换为您实际的FTP服务器信息。此外,代码中使用的是基本的FTP功能,如果需要更复杂的功能,可以根据ftplib库的文档进行扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值