【发布时间】:2019-04-15 05:28:32
【问题描述】:
我想直接从 FTP 服务器读取 WAV 文件(在我的 FTP 服务器中),而不用 Python 将它下载到我的 PC 中。有可能吗?如果可以,怎么做?
我尝试了这个解决方案Read a file in buffer from ftp python,但没有奏效。我有 .wav 音频文件。我想读取该文件并从该 .wav 文件中获取详细信息,例如文件大小、字节速率等。
我能够在本地读取 WAV 文件的代码:
import struct
from ftplib import FTP
global ftp
ftp = FTP('****', user='user-****', passwd='********')
fin = open("C3.WAV", "rb")
chunkID = fin.read(4)
print("ChunkID=", chunkID)
chunkSizeString = fin.read(4) # Total Size of File in Bytes - 8 Bytes
chunkSize = struct.unpack('I', chunkSizeString) # 'I' Format is to to treat the 4 bytes as unsigned 32-bit inter
totalSize = chunkSize[0]+8 # The subscript is used because struct unpack returns everything as tuple
print("TotalSize=", totalSize)
【问题讨论】:
-
所以你只有有一个 FTP 服务器,而不是 HTTP?
-
@MartinPrikryl 我能够在本地获取详细信息,但是当我尝试使用上面的解决方案时,我无法仅读取 wav 文件。如果我设法从 FTP 读取 WAV 文件,那么我现在如何获取 WAV 文件的详细信息
-
@MartinPrikryl 我已经完成了编辑。现在可以看到了
-
@MartinPrikryl 是的
-
@MartinPrikryl 好吧,对不起。你能帮我吗
标签: python python-2.7 ftp wav ftplib