Skip to content

Commit 2a2a0e6

Browse files
committed
Skip invalid filenames
1 parent 65c90d9 commit 2a2a0e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createReadStream, createWriteStream, mkdir, readdir, stat, open, close, unlink } from "fs"
2-
import { join } from "path"
2+
import { basename, join } from "path"
33
import { Readable, Writable } from "stream"
44
import { connect as connectTLS, ConnectionOptions as TLSConnectionOptions } from "tls"
55
import { promisify } from "util"
@@ -704,6 +704,12 @@ export class Client {
704704
protected async _downloadFromWorkingDir(localDirPath: string): Promise<void> {
705705
await ensureLocalDirectory(localDirPath)
706706
for (const file of await this.list()) {
707+
const hasInvalidName = !file.name || basename(file.name) !== file.name
708+
if (hasInvalidName) {
709+
const safeName = JSON.stringify(file.name)
710+
this.ftp.log(`Invalid filename from server listing, will skip file. (${safeName})`)
711+
continue
712+
}
707713
const localPath = join(localDirPath, file.name)
708714
if (file.isDirectory) {
709715
await this.cd(file.name)

0 commit comments

Comments
 (0)