diff --git a/src/vs/workbench/services/files/electron-browser/ftpFileSystemProvider.ts b/src/vs/workbench/services/files/electron-browser/ftpFileSystemProvider.ts index 78c1581eb529e8c456ed33aab9bcc893b996b014..2867b30db593c63794868f070cc193b52ed90923 100644 --- a/src/vs/workbench/services/files/electron-browser/ftpFileSystemProvider.ts +++ b/src/vs/workbench/services/files/electron-browser/ftpFileSystemProvider.ts @@ -12,7 +12,7 @@ import * as JSFtp from 'jsftp'; import { ninvoke } from 'vs/base/common/async'; import { TPromise } from 'vs/base/common/winjs.base'; import { Readable } from 'stream'; -import { join } from 'path'; +import { join, dirname, basename } from 'path'; import { IStat, FileType, IFileSystemProvider } from 'vs/platform/files/common/files'; import { IProgress } from 'vs/platform/progress/common/progress'; @@ -34,27 +34,32 @@ export class FtpFileSystemProvider implements IFileSystemProvider { } stat(resource: URI): TPromise { + const { path } = resource; + if (path === '/') { + // root directory + return TPromise.as({ + type: FileType.Dir, + resource, + mtime: 0, + size: 0 + }); + } - return ninvoke(this._connection, this._connection.ls, resource.path).then(entries => { - - if (entries.length === 1) { - // stat one file - const [entry] = entries; + const name = basename(path); + const dir = dirname(path); + return ninvoke(this._connection, this._connection.ls, dir).then(entries => { + for (const entry of entries) { + if (entry.name === name) { return { resource, mtime: entry.time, size: entry.size, - type: FileType.File + type: entry.type }; } - - // stat directory - return { - resource, - mtime: 0, - size: 0, - type: FileType.Dir, - }; + } + console.log(entries, name, resource); + throw new Error(`NotFound: ${resource.path}`); }); } diff --git a/src/vs/workbench/services/files/electron-browser/jsftp.d.ts b/src/vs/workbench/services/files/electron-browser/jsftp.d.ts index 767a28e7abd6b485d1bd93a5a7c7b958b3944eef..59bfce7a3c5f773c240e3d1c76273703c904b853 100644 --- a/src/vs/workbench/services/files/electron-browser/jsftp.d.ts +++ b/src/vs/workbench/services/files/electron-browser/jsftp.d.ts @@ -1,6 +1,7 @@ import { Readable } from 'stream'; +import { EventEmitter } from 'events'; declare namespace JSFtp { @@ -10,6 +11,7 @@ declare namespace JSFtp { port?: number | 21; user?: string | 'anonymous'; pass?: string | '@anonymous'; + useList?: boolean } interface Callback { @@ -25,11 +27,13 @@ declare namespace JSFtp { } } -interface JSFtp { +interface JSFtp extends EventEmitter { keepAlive(wait?: number): void; ls(path: string, callback: JSFtp.Callback): void; + list(path: string, callback: JSFtp.Callback): void; put(buffer: Buffer, path: string, callback: JSFtp.Callback): void; get(path: string, callback: JSFtp.Callback): void; + setType(type: 'A' | 'AN' | 'AT' | 'AC' | 'E' | 'I' | 'L', callback: JSFtp.Callback): void; raw(command: string, args: any[], callback: JSFtp.Callback): void }