使用SFTP删除远程文件的部分

发布于 2025-02-13 11:52:52 字数 433 浏览 1 评论 0原文

我想使用SFTP协议删除文件的一部分。示例:

这是示例文本。 - > 这是文本。

标准协议写操作将偏移和一串数据作为输入。但是,该接口未指定文件长度以可能从文件中删除字符。这样,文件只能在大小上生长。在上面的示例中,如果我试图使用写入更新文件,则结果输出将是:

这是文本。

在sftp中删除字符的正确方法是什么?是否有一个终止字符,用于使用写入时用来发出文件的结尾?还是我只需要删除整个文件并重新上传一个新文件?

I would like to remove a portion of a file using the SFTP protocol. Example:

This is a sample text. --> This is a text.

The standard protocol write operation takes an offset and a string of data as inputs. However, the interface does not specify a file length to possibly remove characters from the file. That way the file can only ever grow in size. In the above example, if I attempted to update the file using write, the resulting output would be:

This is a text.e text.

What is the proper way of removing characters in SFTP? Is there perhaps a terminating character which is used to signal the end of a file when using write? Or do I have to just delete the entire file and re-upload a new one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停滞 2025-02-20 11:52:52

您无法删除文件内容的一部分。甚至不是从本地文件中,仅从sftp上的远程文件中。

您必须覆盖文件 - 或至少从第一个更改字节开始的文件的整个部分。然后将文件截断,以防新内容短于原始内容。

您可以使用copy-data sftp扩展名来复制文件本身中的数据,以避免需要重新上传现有内容。如果您的SFTP服务器支持扩展程序。在Openssh中,仅在最近的

You cannot remove a part of a file contents. Not even from a local file, let only from a remote file over SFTP.

You have to overwrite the file – or at least whole part of the file starting with the first changed byte. And then truncate the file, in case the new contents is shorter than the original.

You can use copy-data SFTP extension to copy data within the file itself to avoid need to reupload the existing contents. If your SFTP server supports the extension. In OpenSSH, it's supported only in very recent version 9.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文